package org.dataframework.security.core.expression;

import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.operators.conditional.AndExpression;
import net.sf.jsqlparser.expression.operators.relational.*;
import org.dataframework.security.core.Operators;

/**
 * @Author: LiuCf
 * @Email: 1316640406@qq.com
 * @Date: 2021/7/3 12:02
 */
public class ExpressionUtils {
    public static Expression ofOperators(Operators operators) {
        String operator = null;
        if (operators == null || (operator = operators.getOperator()) == null) {
            return null;
        }

        switch (operator) {
            case "HIDDEN":
                return new HiddenExpression();
            case "EQUALS":
                return new EqualsTo();
            case "NOT_EQUALS":
                return new NotEqualsTo();
            case "GREATER_THAN":
                return new GreaterThan();
            case "MINOR_THAN":
                return new MinorThan();
            case "GREATER_EQUALS":
                return new GreaterThanEquals();
            case "MINOR_EQUALS":
                return new MinorThanEquals();
            case "IS_NULL":
                return new IsNullExpression();
            case "IS_NOT_NULL":
                return new IsNullExpression().withNot(true);
            case "FULL_LIKE":
                return new LikeExpression();
            case "NOT_LIKE":
                return new LikeExpression().withNot(true);
            case "IN":
                return new InExpression();
            case "NOT_IN":
                return new InExpression().withNot(true);
            case "BETWEEN":
                return new Between();
            case "CUSTOMIZE":
                return new AndExpression();
            default:
        }

        return null;
    }
}
